﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess.Repository;
using DataAccess.Repository.Interface;
using DataAccess.Models;

namespace KPI
{
    public partial class DynamicWorkDetail : BasePage
    {
        private IDynamicWorkRepository ipd = new DynamicWorkRepository();
        public int wnid
        {
            get
            {
                return CommonHelper.QueryStringInt("wnid");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var u = KPISiteContext.Current.CurrentUser;
                if (u != null && u.RoleName == "administrators")
                {
                    this.btnEdit.Visible = true;
                }

               WorkNews wnDetail = ipd.GetDetailWorkNews(wnid);
               if (wnDetail != null)
                {
                    this.lbTitle.Text = wnDetail.WorkNewsTitle;
                    this.LbAddtime.Text = wnDetail.WorkNewsAddTime.Value.ToString("yyyy-MM-dd HH:mm");
                    this.PanelDetail.InnerHtml = wnDetail.WorkNewsContent;
                }
            }
        }

        /// <summary>
        /// 返回事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/DynamicWorksList.aspx");
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/AddDynamicWork.aspx?id=" + this.wnid.ToString());
        }
    }
}